﻿@model MvcEditorModel
<div class="input-group">
    <input type="text" id="@(Model.Metadata.ClrName)_Name" readonly="readonly" class="form-control" value="@Model.Value">
    <input type="hidden" id="@(Model.Metadata.ClrName)_Value" name="@Model.Metadata.ClrName" value="@(Model.Value != null? ((Wodsoft.ComBoost.Data.Entity.EntityBase)Model.Value).Index.ToString() : "")" />
    <span class="input-group-btn">
        <button id="@(Model.Metadata.ClrName)_Select" class="btn btn-default" type="button">选择</button>
        <button id="@(Model.Metadata.ClrName)_Clear" class="btn btn-default" type="button">清空</button>
    </span>
</div>
<script type="text/javascript">
    $(function () {
        var name = $('#@(Model.Metadata.ClrName)_Name');
        var value = $('#@(Model.Metadata.ClrName)_Value');
        $('#@(Model.Metadata.ClrName)_Select').click(function () {
            if (window.showModalDialog != undefined) {
                var result = window.showModalDialog('@Url.RouteUrl(new { controller = Model.Metadata.ClrType.Name, action = "Selector" })',
                    null,
                    'dialogHeight:720px;dialogWidth:1024px');
                if (result == undefined)
                    result = window.returnValue;
                if (result == null)
                    return;
                name.val(result.name);
                value.val(result.value);
            }
            else {
                window.open('@Url.RouteUrl(new { controller = Model.Metadata.ClrType.Name, action = "Selector" })',
                    null,
                    'dialog=1,modal=1,location=0,menubar=0,resizable=0,scrollbars=0,status=0,toolbar=0,height=720,width=1024')
            }
            window.selectCompleted = function (result) {
                name.val(result.name);
                value.val(result.value);
            }
        });
        $('#@(Model.Metadata.ClrName)_Clear').click(function () {
            name.val('');
            value.val('');
        });
    });
</script>